package com.qbw.app.module.vehicle.holder;

import android.content.Context;
import androidx.databinding.ViewDataBinding;
import android.view.ViewGroup;

import com.qbw.app.Constant;
import com.qbw.app.R;
import com.qbw.app.databinding.VehicleHolderSelectVehicleItemBinding;
import com.qbw.app.model.Vehicle;
import com.qbw.app.module.common.holder.CommonHolder;

import java.util.Locale;

/**
 * @author QBW
 * @date 2019-09-01
 */
public class VehicleSelectVehicleItemHolder extends CommonHolder<Vehicle, VehicleHolderSelectVehicleItemBinding> {

    public VehicleSelectVehicleItemHolder(Context context, ViewGroup viewParent, Object listener) {
        super(context, R.layout.vehicle_holder_select_vehicle_item, viewParent, listener);
    }

    @Override
    public void bindData(int position, Vehicle data) {
        super.bindData(position, data);
        mBinding.tv.setText(data.getVehicleNick() + (data.getDrivingState() == Constant.VEHICLE_STATUS_OFFLINE ? (String
                .format(Locale.getDefault(),
                        "(%s)",
                        mContext.getResources().getString(R.string.offline))) : ""));
        itemView.setOnClickListener(mClickListenerItem);
    }

    @Override
    protected void onClickItem() {
        super.onClickItem();
        if (mListener instanceof Listener) {
            ((Listener) mListener).onSelectVehicle(mData);
        }
    }

    public interface Listener {
        void onSelectVehicle(Vehicle vehicle);
    }
}
